package homework.ch11_13.p3;

public class Person implements Cloneable {
    private  int age;
    private  String name;

    public Person() {
    }

    public Person(int age, String name) {
        this.age = age;
        this.name = name;
    }
    //克隆
    public Object clone() throws CloneNotSupportedException{
        Person p=(Person)super.clone();
        p.age=this.age;
        p.name=this.name;
        return p;
    }

    public boolean equals(Object obj){
        int flag=0;
        if(obj instanceof Person){
            if(this.age!=((Person)obj).age)
                return false;
            Person o=(Person) obj;
            if(this.name.equals(o.name)) {
                flag=1;
            }
        }
        return flag==1?true:false;
    }

    public int getAge() {
        return this.age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString(){

        return "name:"+this.name+','+" age="+this.age+',';
    }
}
